<template>
  <!-- 获取用户信息
     1：定义接口api
     2:导入接口api方法
     3：进入页面请求api
     4:存储数据并渲染 -->
  <div class="mine">
    <!-- <button @click="$router.push('/layout/mine')">跳转到我的页面</button> -->
    <div class="top">
      <img class="avatar" :src="info.photo" alt="" />
      <div class="info">
        <h3>{{ info.name }}</h3>
        <div class="birthday">{{ info.birthday }}</div>
      </div>
    </div>
    <div class="middle">
      <div class="item">
        <van-icon name="newspaper-o c1" />
        <div class="name">我的作品</div>
      </div>
      <div class="item">
        <van-icon name="star-o c2" />
        <div class="name">我的收藏</div>
      </div>
      <div class="item">
        <van-icon name="tosend c3" />
        <div class="name">阅读历史</div>
      </div>
    </div>
    <div class="bottom">
      <van-cell-group>
        <van-cell
          title="编辑资料"
          icon="edit"
          is-link
          @click="$router.push('/mine/edit')"
        />
        <van-cell to="/chat" title="小智同学" icon="chat-o" is-link />
        <van-cell title="系统设置" icon="setting-o" is-link />
        <van-cell title="退出登录" icon="info-o" is-link @click="exit" />
      </van-cell-group>
    </div>
  </div>
</template>
<script>
// import { userProfile } from '@/api/mine'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      userInfo: ''
    }
  },
  computed: {
    // ...mapState(['userInfo'])
    ...mapState({
      info: 'userInfo'
    })
  },
  async created () {
    // const res = await userProfile()
    // this.userInfo = res.data
    // 存储到vuex
    // this.$store.commit('setUserInfo', res.data)
    // console.log('用户信息', res)
    this.$store.dispatch('getUserInfo')
  },
  methods: {
    exit () {
      // 清除token
      this.$store.commit('logout')
      // 跳转到登录页
      this.$router.push('/login')
      // 提示
      this.$toast.success('退出登录成功')
    }
  }
}
</script>
<style lang="less" scoped>
.top {
  height: 90px;
  background-color: #3296fa;
  display: flex;
  align-items: center;
  padding: 20px;
  .avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
  }
  .info {
    color: #fff;
    margin-left: 10px;
    .birthday {
      background-color: #fff;
      color: #3296fa;
      margin-top: 5px;
    }
  }
}
.middle {
  display: flex;
  padding: 15px 0;
  justify-content: space-around;
  .item {
    text-align: center;
    .van-icon {
      font-size: 30px;
      padding-bottom: 10px;
    }
    .c1 {
      color: #94afff;
    }
    .c2 {
      color: #ff3800;
    }
    .c3 {
      color: #ffb45b;
    }
  }
}
</style>
